package com.guli.oss.controller;

import com.guli.commonUtils.R;
import com.guli.oss.service.impl.FileServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author zxc
 * @date 2023/04/01 15:41
 **/
@Api(description = "阿里云文件管理")
@RestController
@RequestMapping("/edu/fileOss")
//@CrossOrigin // 解决跨域问题
public class FileController {
    @Autowired
    FileServiceImpl fileService;

    // 文件上传到阿里云OSS中
    @ApiOperation(value = "上传文件到阿里云OSS")
    @PostMapping("upload")
    public R uploadFile(
            // 需要注意的是，@ApiParam注解中name属性需要和所要传递的参数file名称一致，否则会出现找不到文件错误;
            @ApiParam(name = "file" , value = "上传文件" , required = true)
            MultipartFile file){
        //获取所要上传的文件 MultipartFile
        // 返回该文件所上传到OSS的路径;
        String url = fileService.uploadFile(file);
        return R.ok().data("url" , url);
    }
}
